﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Amazon.DynamoDBv2.DocumentModel;

namespace AmazonDynamoDBStub.Extensions
{
    public static class DynamoDBEntryExtensions
    {
        public static string GetAttributeType(this DynamoDBEntry entry)
        {
            if (entry == null)
            {
                throw new ArgumentNullException("entry");
            }

            Primitive primitive;
            PrimitiveList primitiveList;

            if ((primitive = entry.AsPrimitive()) != null)
            {
                switch (primitive.Type)
                {
                    case DynamoDBEntryType.Binary:
                        return "B";
                    case DynamoDBEntryType.Numeric:
                        return "N";
                    case DynamoDBEntryType.String:
                        return "S";
                }
            }
            else if ((primitiveList = entry.AsPrimitiveList()) != null)
            {
                switch (primitiveList.Type)
                {
                    case DynamoDBEntryType.Binary:
                        return "BS";
                    case DynamoDBEntryType.Numeric:
                        return "NS";
                    case DynamoDBEntryType.String:
                        return "SS";
                }
            }

            throw new NotSupportedException("DynamoDBEntry has neither Primitive nor PrimitiveList value.");
        }
    }
}
